#pragma once

#include <functional>
#include <QString>
#include <QThread>
#include <QAtomicInteger>
#include "qtc_alarm_core/AlarmEvent.h"

namespace qtc_alarm_kafka {

class AlarmKafkaConsumer : public QThread {
  Q_OBJECT
public:
  using EventCallback = std::function<void(const qtc_alarm_core::AlarmEvent&)>;

  struct Config {
    QString broker;
    QString topic_state;
    QString topic_cmd;
    QString topic_config;
    QString group_id;
    QString root_filter; // only accept events under this root
  };

  explicit AlarmKafkaConsumer(const Config& cfg, EventCallback cb);
  ~AlarmKafkaConsumer() override;

  void stop();

protected:
  void run() override;

private:
  Config m_cfg;
  EventCallback m_cb;
  QAtomicInteger<bool> m_running {true};
};

} // namespace qtc_alarm_kafka